/**
 * Copyright (C) 2013-2014 the original author or authors.
 */
package com.foreveross.bsl.common.utils.exception;
/**
 * @description
 *
 * @author rening
 * @version v1.0
 *
 * @2013-8-9
 *
 */
public class ApplicationException extends RuntimeException {

	private static final long serialVersionUID = 1L;
	
	private String code;
	
	private String message;
	
	/**
	 * the default constructor generate System Error
	 */
	public ApplicationException(){
		this.code = AppExcType.SYSTEM_ERROR_CODE;
		this.message = "System Error";
	}
	
	/**
	 * generate global Error or exception
	 */
	public ApplicationException(String type){
		if("1".equals(type)){
			this.code = AppExcType.SYSTEM_ERROR_CODE;
			this.message = "System Error";
		} else {
			this.code = AppExcType.BUS_ERROR_CODE;
			this.message = "business exception";
		}
	}
	
	public ApplicationException(String type, String layer, String modul, String code, String message, Throwable cause){
		super(message, cause);
		this.code = new StringBuffer().append(type).append(layer).append(modul).append(code).toString();
		this.message = message;
	}
	
	public ApplicationException(String type, String layer, String modul, String code, String message){
		super(message);
		this.code = new StringBuffer().append(type).append(layer).append(modul).append(code).toString();
		this.message = message;
	}

	public ApplicationException(String type, String layer, String modul, String code, Throwable cause){
		super(cause);
		this.code = new StringBuffer().append(type).append(layer).append(modul).append(code).toString();
	}
	
	public ApplicationException(String code, String message, Throwable cause){
		super(message, cause);
		this.code = code;
		this.message = message;
	}
	
	public ApplicationException(String code, String message){
		super(message);
		this.code = code;
		this.message = message;
	}
	
	public String getCode() {
		return code;
	}

	public void setCode(String type, String modul) {
		this.code = type + modul;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

}
